package com.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MQConfig {

    public  static final String DIRECT_ECHANGE="s2020_02_DirectExchange";


public  static final String  QUEUE_MIAOSHA="s2020_02_QUEUE_MIAOSHA";

public static final String QUEUE_SENDMESSAGE="QUEUE_SENDMESSAGE";

public static final String KEY_MIAOSHA="s2020_02_KEY_MIAOSHA";
public static final String KEY_SENDMESSAGE="s2020_02_KEY_SENDMESSAGE";

    /**
     * 直接型交换机
     * @return
     */
    @Bean
    public DirectExchange createDirectExchange(){
        return new DirectExchange(DIRECT_ECHANGE);
    }

    /**
     * 这是主题交换机
     * @return
     */
    @Bean
    public TopicExchange createTopicExchange(){
        return new TopicExchange("这是主题交换机");
    }


    /**
     * 创建秒杀队列
     * @return
     */
    @Bean
    public Queue createQueu_USEE_MIAOSHA(){

        return new Queue(QUEUE_MIAOSHA);
    }

    /**
     * 创建发信息队列
     * @return
     */
    @Bean
    public Queue createQueu_QUEUE_SENDMESSAGE(){
        return new Queue(QUEUE_SENDMESSAGE);
    }

    /**
     * 直连交换机绑定秒杀队列
     * @return
     */
    @Bean
    public Binding binding__________DIRECT_EXCHANGE_______MIAOSHA(){
        return BindingBuilder.bind(createQueu_USEE_MIAOSHA()).to(createDirectExchange()).with(KEY_MIAOSHA);
    }


    /**
     * 直连交换机绑定秒杀队列
     * @return
     */
    @Bean
    public Binding binding__________DIRECT_EXCHANGE_______SENDMESSAGE(){
        return BindingBuilder.bind(createQueu_QUEUE_SENDMESSAGE()).to(createDirectExchange()).with(KEY_SENDMESSAGE);
    }


    @Bean
    public Binding binding_________TopicExchange_______SENDMESSAGE(){
        return BindingBuilder.bind(createQueu_QUEUE_SENDMESSAGE()).to(createTopicExchange()).with("com.#");
    }






}
